#!/usr/bin/env python
# coding: utf-8

'''
重定向
'''
import tornado.web
import tornado.httpserver
import tornado.ioloop
from tornado.web import url,RequestHandler

class IndexHandler(RequestHandler):
    def get(self, *args, **kwargs):
        stu = {
            "name": "王尼玛",
            "age": 2333,
            "gender": 1
        }
        '''write方法会自动将字典转换为json格式，并且加上响应头：
        Content-Type:application/json; charset=UTF-8'''
        self.write(stu)

class LoginHandler(RequestHandler):
    def get(self, *args, **kwargs):
        self.write("<form method='post'><input type='submit' value='login' /></form>")
    def post(self, *args, **kwargs):
        self.redirect(self.reverse_url('index'))
if __name__ == '__main__':
    app = tornado.web.Application([
        url(r'/', IndexHandler, name='index'),
        url(r'/login', LoginHandler, name='login')
    ], debug=True)
    http_server = tornado.httpserver.HTTPServer(app)
    http_server.bind(8000)
    http_server.start(1)
    tornado.ioloop.IOLoop.current().start()